package com.tac.service.mes.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.tac.common.result.Result;
import com.tac.dao.mes.ProductionCompletionDao;
import com.tac.pojo.mes.ProductionCompletion;
import com.tac.service.mes.ProductionCompletionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

@Service
public class ProductionCompletionServiceImpl implements ProductionCompletionService {

    @Autowired
    private ProductionCompletionDao productionCompletionDao;

    //生产完工单查询
    public Result<PageInfo<ProductionCompletion>> getList(Integer pageNum,Integer pageSize,Integer productionPlanId, String productionOperation, Integer materialId,
                          Date completionDateStart, Date completionDateEnd, String batchNumber, String status){
        PageHelper.startPage(pageNum,pageSize);
        List<ProductionCompletion> list = productionCompletionDao.getList(productionPlanId, productionOperation, materialId, completionDateStart, completionDateEnd, batchNumber, status);
        PageInfo<ProductionCompletion> productionCompletionPageInfo = new PageInfo<>(list);
        return Result.success(productionCompletionPageInfo);
    }
    //生产完工单添加
    public Result save(ProductionCompletion productionCompletion){
        Integer integer = productionCompletionDao.save(productionCompletion);
        if(integer<=0){
            return Result.error("生产完工单添加失败");
        }
        return Result.success(null);
    }
    //生产完工单删除
    public Result remove(List<Integer> ids){
        Integer integer = productionCompletionDao.remove(ids);
        if(integer<=0){
            return Result.error("生产完工单删除失败");
        }
        return Result.success(null);
    }
    //生产完工单更新
    public Result update(ProductionCompletion productionCompletion){
        Integer integer = productionCompletionDao.update(productionCompletion);
        if(integer<=0){
            return Result.error("生产完工单更新失败");
        }
        return Result.success(null);
    }
}
